<template>
	<scroll-view scroll-y="true" class="scroll-Y" refresher-enabled="true" refresher-background="#f6f6f6"
		:refresher-triggered="refresherStatus" @refresherrefresh="_refresherrefresh" @scrolltolower="_scrolltolower">
		<view class="scroll-content">
			<view class="scroll-item" v-for="item in list" :key="item.tradeId">
				<view class="scroll-item__line">
					<view class="scroll-item__line__left">
						{{$t('order.Sell-Currency')}}
					</view>
					<view class="scroll-item__line__right">
						{{item.sourceCurrencyVo.currency}}
					</view>
				</view>
				<view class="scroll-item__line">
					<view class="scroll-item__line__left">
						{{$t('order.Quantity')}}
					</view>
					<view class="scroll-item__line__right">
						{{ parseFloat(item.totalStock)  }}
					</view>
				</view>
				<view class="scroll-item__line" v-if="item.status ==1">
					<view class="delist-box" v-if="item.shelfStatus == 0">
						{{$t('information.HasBeenRemoved')}}
					</view>
					<view class="scroll-item__line__right scroll-item__line__btnbox">
						<view class="del-btn" @click="delOder(item)">{{$t('index.Delete')}}</view>
						<view style="width: 20rpx;" v-if="item.shelfStatus == 1"></view>
						<view class="edit-btn" v-if="item.shelfStatus == 1" @click="editOder(item)">{{$t('index.Edit')}}</view>
					</view>
				</view>
			</view>
		</view>
	</scroll-view>
</template>

<script>
	import {
		getTradeList,
		setShelfStatus
	} from '@/services/bourse.js'
	import {
		mapState,
		mapMutations
	} from "vuex";
	export default {
		data() {
			return {
				refresherStatus: false,
				otherParmas: {
					tradeScene: 1,
					pageSize: 10,
					pageNum: 1,
					userId: '',
					status: 1
				},
				list: [],
				total: 0,
			}
		},
		computed: {
			...mapState(['userInfo'])
		},
		mounted() {
			this._getTradeList()
		},
		methods: {
			...mapMutations(["SET_CURRENT_ORDER_INFO"]),
			async _getTradeList(val) {
				this.otherParmas.userId = this.userInfo.userId
				const {
					success,
					result
				} = await getTradeList(this.otherParmas)
				this.refresherStatus = false
				if (success) {
					if (val) {
						this.list = [...this.list, ...result.rows]
						this.total = result.total
					} else {
						this.list = result.rows
						this.total = result.total
					}
				}
			},
			// 编辑
			async editOder(item) {
				// 先下架,再编辑
				const {
					success,
					result
				} = await setShelfStatus({
					"tradeId": item.tradeId,
					"shelfStatus": 0
				})
				if (success) {
					this.SET_CURRENT_ORDER_INFO(item)
					uni.navigateTo({
						url: '/pagesUser/bourse/releaseCashOut?isEdit=1'
					})
				}
			},
			// 删除
			delOder(item) {
				this.$emit('deletePosted', item)
			},
			_refresherrefresh() {
				this.refresherStatus = true
				this.otherParmas.pageNum = 1
				this._getTradeList()
			},
			_scrolltolower() {
				if (this.list.length < this.total) {
					this.otherParmas.pageNum++
					this._getTradeList(1)
					return
				}
				console.log('触底了');
			}
		}
	}
</script>

<style scoped lang="scss">
	.delist-box {
		position: absolute;
		top: 50%;
		transform: translateY(-50%);
		color: red;
	}

	.scroll-Y {
		height: calc(100vh - 44px - var(--status-bar-height))
	}

	.scroll-content {
		padding: 30rpx;

		.scroll-item:last-child {
			margin-bottom: 0;
		}

		.scroll-item {
			color: #878787;
			font-size: 28rpx;
			font-family: HarmonyOS Sans-Regular, HarmonyOS Sans;
			font-weight: 400;
			background-color: #FFFFFF;
			border-radius: 20rpx;
			padding: 30rpx;
			margin-bottom: 30rpx;

			&__line:last-child {
				margin-bottom: 0;
			}

			&__line {
				position: relative;
				display: flex;
				margin-bottom: 20rpx;

				&__left {}

				&__right {
					font-weight: 500;
					color: #606665;
					margin-left: auto
				}

				&__btnbox {
					display: flex;

					.del-btn,
					.edit-btn {
						padding: 12rpx 24rpx;
						line-height: 40rpx;
					}

					.del-btn {
						border-radius: 64rpx;
						border: 2rpx solid rgba(135, 135, 135, 0.6);
						color: #878787;
					}

					.edit-btn {
						background: #61BDB2;
						border-radius: 64rpx;
						color: #FFFFFF;
					}
				}
			}
		}
	}
</style>